number = int(input())
num = 0
g = False
b1 = 0
b2 = 1
for i in range (1, 5):
    a = int((str(number)[b1:b2]))
    for i in range (2, a // 2 + 1): 
        if (a % i != 0):
            g = True
        else:
            g = False
            break
    if a == 2 or a == 3:
        g = True
    if g == True:
        num = max(a, num)
    b1 = b1 + 1 
    b2 = b2 + 1
b1 = 0
b2 = 2
for i in range (1, 4):
    a = int((str(number)[b1:b2]))
    for i in range (2, a // 2 + 1): 
        if (a % i != 0):
           g = True
        else:
           g = False
        break
    if a == 2 or a == 3:
        g = True
    if g == True:
        num = max(a, num)
    b1 = b1 + 1 
    b2 = b2 + 1
b1 = 0
b2 = 3
for i in range (1, 3):
    a = int((str(number)[b1:b2]))
    for i in range (2, a // 2 + 1): 
        if (a % i != 0):
            g = True
        else:
            g = False
            break
    if a == 2 or a == 3:
        g = True
    if g == True:
        num = max(a, num)
    b1 = 1 + 1 
    b2 = b2 + 1
b1 = 0
b2 = 4
for i in range (1, 2):
    a = int((str(number)[b1:b2]))
    for i in range (2, a // 2 + 1): 
        if (a % i != 0):
            g = True
        else:
            g = False
            break
    if a == 2 or a == 3:
        g = True
    if g == True:
        num = max(a, num)
    b1 = b1 + 1 
    b2 = b2 + 1
print(num)
print(" ")
